package com.example.base;

import java.time.DayOfWeek;
import java.time.LocalDate;

/**
 * 日历
 * 这段程序为了展示使用一个类的接口来实现复杂需求，而不需要关注其细节
 */
public class Date {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        int month = date.getMonthValue();
        int today = date.getDayOfMonth();
        int year  = date.getYear();
        System.out.println(year + "-" + month + "-" + today);
        //将date设置为这个月的第一天
        date = date.minusDays(today - 1);
        DayOfWeek weekday = date.getDayOfWeek();
        int value = weekday.getValue();//星期几

        //打印表头和第一行的缩进
        System.out.println("Mon Tue Wed Thu Fri Sat Sun");
        for(int i = 1; i < value; i++){
            System.out.println("    ");
        }
        while(month == date.getMonthValue()){
            System.out.printf("%3d", date.getDayOfMonth());
            if(date.getDayOfMonth() == today){
                System.out.print("*");
            }else{
                System.out.print(" ");
            }
            date = date.plusDays(1);
            if(date.getDayOfWeek().getValue() == 1){
                System.out.println();
            }
        }
    }
}
